<?php
/**
*
* @package Search Topic JQAutocomplete
* @version 1.0.0
* @copyright (c) 2010 velocat, www.velocat.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

define('IN_PHPBB', true);

$phpbb_root_path = '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin(false);
$auth->acl($user->data);
$user->setup();

// Obtain working mode
$mode = request_var('mode', '');
$config['search_user_num'] = 50; //Set number of search results

if ($mode == 'search_username')
{
	$q = strtolower(utf8_normalize_nfc(request_var('q' ,'', true)));
	if(!$q)
	{
		exit();
	}	
	else
	{
		$sql_where = 'AND username_clean ' . $db->sql_like_expression(utf8_clean_string($q) . $db->any_char);

		$sql = "SELECT user_id, username
			FROM " . USERS_TABLE . " 	
			WHERE user_id > 1 
				$sql_where
			ORDER BY username";

		$result = $db->sql_query_limit($sql,$config['search_user_num']);

		$user_list = array();

		while ($row = $db->sql_fetchrow($result))
		{
			$user_id = (int)$row['user_id'];
			if (strpos(utf8_strtolower($row['username']), $q) !== false) 
			{
				echo  $row['username'] ."|$user_id\n";
			}
		}
		$db->sql_freeresult($result);
	}
}
?>